<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>软工项目——词频统计</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta property="og:type" content="website">
<meta property="og:title" content="软工项目——词频统计">
<meta property="og:url" content="http://wx_mr_sanghy.gitee.io/blog/index.html">
<meta property="og:site_name" content="软工项目——词频统计">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Huanyu Sang">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/blog/atom.xml" title="软工项目——词频统计" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
    
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">软工项目——词频统计</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/blog/" id="subtitle">桑环宇 1120183339</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/blog/">Home</a>
        
          <a class="main-nav-link" href="/blog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/blog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://wx_mr_sanghy.gitee.io/blog"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main">
  
    <article id="post-photo" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/blog/2021/02/06/photo/" class="article-date">
  <time class="dt-published" datetime="2021-02-06T11:34:32.791Z" itemprop="datePublished">2021-02-06</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 itemprop="name">
      <a class="p-name article-title" href="/blog/2021/02/06/photo/">软工个人项目——词频统计</a>
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>1120183339 桑环宇</p>
<h2 id="1-PSP表格"><a href="#1-PSP表格" class="headerlink" title="1, PSP表格"></a>1, PSP表格</h2><table>
<thead>
<tr>
<th align="center">PSP2.1</th>
<th align="center">Personal Software Process Stages</th>
<th align="center">预估耗时（分钟）</th>
<th align="center">实际耗时（分钟）</th>
</tr>
</thead>
<tbody><tr>
<td align="center">Planning</td>
<td align="center">计划</td>
<td align="center">10</td>
<td align="center">40</td>
</tr>
<tr>
<td align="center">· Estimate</td>
<td align="center">· 估计这个任务需要多少时间</td>
<td align="center">10</td>
<td align="center">40</td>
</tr>
<tr>
<td align="center">Development</td>
<td align="center">开发</td>
<td align="center">375</td>
<td align="center">420</td>
</tr>
<tr>
<td align="center">· Analysis</td>
<td align="center">· 需求分析 (包括学习新技术)</td>
<td align="center">30</td>
<td align="center">20</td>
</tr>
<tr>
<td align="center">· Design Spec</td>
<td align="center">· 生成设计文档</td>
<td align="center">30</td>
<td align="center">35</td>
</tr>
<tr>
<td align="center">· Design Review</td>
<td align="center">· 设计复审 (和同事审核设计文档)</td>
<td align="center">30</td>
<td align="center">60</td>
</tr>
<tr>
<td align="center">· Coding Standard</td>
<td align="center">· 代码规范 (为目前的开发制定合适的规范)</td>
<td align="center">20</td>
<td align="center">15</td>
</tr>
<tr>
<td align="center">· Design</td>
<td align="center">· 具体设计</td>
<td align="center">45</td>
<td align="center">60</td>
</tr>
<tr>
<td align="center">· Coding</td>
<td align="center">· 具体编码</td>
<td align="center">100</td>
<td align="center">120</td>
</tr>
<tr>
<td align="center">· Code Review</td>
<td align="center">· 代码复审</td>
<td align="center">60</td>
<td align="center">30</td>
</tr>
<tr>
<td align="center">· Test</td>
<td align="center">· 测试（自我测试，修改代码，提交修改）</td>
<td align="center">60</td>
<td align="center">80</td>
</tr>
<tr>
<td align="center">Reporting</td>
<td align="center">报告</td>
<td align="center">80</td>
<td align="center">90</td>
</tr>
<tr>
<td align="center">· Test Report</td>
<td align="center">· 测试报告</td>
<td align="center">50</td>
<td align="center">60</td>
</tr>
<tr>
<td align="center">· Size Measurement</td>
<td align="center">· 计算工作量</td>
<td align="center">15</td>
<td align="center">10</td>
</tr>
<tr>
<td align="center">· Postmortem &amp; Process Improvement Plan</td>
<td align="center">· 事后总结, 并提出过程改进计划</td>
<td align="center">15</td>
<td align="center">20</td>
</tr>
<tr>
<td align="center"></td>
<td align="center">合计</td>
<td align="center">465</td>
<td align="center">550</td>
</tr>
</tbody></table>
<h2 id="2-需求分析"><a href="#2-需求分析" class="headerlink" title="2, 需求分析"></a>2, 需求分析</h2><h3 id="需求1："><a href="#需求1：" class="headerlink" title="需求1："></a>需求1：</h3><h4 id="统计出某个英文文本文件中的26个字母出现的频率。"><a href="#统计出某个英文文本文件中的26个字母出现的频率。" class="headerlink" title="统计出某个英文文本文件中的26个字母出现的频率。"></a>统计出某个英文文本文件中的26个字母出现的频率。</h4><p>   <strong>命令行参数</strong>要求：  </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -c &lt;file name&gt;</span><br></pre></td></tr></table></figure>
<p><strong>输出</strong>要求：由高到低排列，并显示字母出现的百分比，精确到小数点后面两位，若两个字母出现的频率一样，则就按照字典序排列。</p>
<h3 id="需求2："><a href="#需求2：" class="headerlink" title="需求2："></a>需求2：</h3><h4 id="统计出某个英文文本文件中的所有不重复的单词。"><a href="#统计出某个英文文本文件中的所有不重复的单词。" class="headerlink" title="统计出某个英文文本文件中的所有不重复的单词。"></a>统计出某个英文文本文件中的所有不重复的单词。</h4><p>   <strong>命令行参数</strong>要求：  </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -f &lt;file name&gt;</span><br></pre></td></tr></table></figure>
<p><strong>输出</strong>要求：按照出现次数由多到少排列，出现次数同样多的，以字典序排列。</p>
<h3 id="需求3："><a href="#需求3：" class="headerlink" title="需求3："></a>需求3：</h3><h4 id="统计出指定文件目录下所有文件各自的所有不重复的单词。"><a href="#统计出指定文件目录下所有文件各自的所有不重复的单词。" class="headerlink" title="统计出指定文件目录下所有文件各自的所有不重复的单词。"></a>统计出指定文件目录下所有文件各自的所有不重复的单词。</h4><p><strong>命令行参数</strong>要求： 无子目录</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -d &lt;directory name&gt;</span><br></pre></td></tr></table></figure>
<p><strong>命令行参数</strong>要求： 有子目录</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -d -s &lt;directory name&gt;</span><br></pre></td></tr></table></figure>
<h3 id="需求4："><a href="#需求4：" class="headerlink" title="需求4："></a>需求4：</h3><h4 id="统计出文件中出现次数最多的前n个单词"><a href="#统计出文件中出现次数最多的前n个单词" class="headerlink" title="统计出文件中出现次数最多的前n个单词"></a>统计出文件中出现次数最多的前n个单词</h4><p><strong>命令行参数</strong>要求：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -f &lt;file name&gt; -n [&lt;<span class="built_in">int</span>&gt;]</span><br><span class="line">wf.exe -d &lt;directory name&gt; -n [&lt;<span class="built_in">int</span>&gt;]</span><br><span class="line">wf.exe -d -s &lt;directory name&gt; -n [&lt;<span class="built_in">int</span>&gt;]</span><br><span class="line">wf.exe -x &lt;stopWordFile name&gt; -f &lt;file name&gt; -n [&lt;<span class="built_in">int</span>&gt;]</span><br></pre></td></tr></table></figure>
<h3 id="需求5："><a href="#需求5：" class="headerlink" title="需求5："></a>需求5：</h3><h4 id="统计出文件中出现非停用词的单词频率"><a href="#统计出文件中出现非停用词的单词频率" class="headerlink" title="统计出文件中出现非停用词的单词频率"></a>统计出文件中出现非停用词的单词频率</h4><p><strong>命令行参数</strong>要求：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -x &lt;stopWordFile name&gt; -f &lt;file name&gt;</span><br></pre></td></tr></table></figure>
<h3 id="需求6："><a href="#需求6：" class="headerlink" title="需求6："></a>需求6：</h3><h4 id="统计出文件中出现指定单词个数的短语频率"><a href="#统计出文件中出现指定单词个数的短语频率" class="headerlink" title="统计出文件中出现指定单词个数的短语频率"></a>统计出文件中出现指定单词个数的短语频率</h4><p><strong>命令行参数</strong>要求：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -f &lt;file name&gt; -p &lt;<span class="built_in">int</span>&gt;</span><br></pre></td></tr></table></figure>
<h3 id="需求7："><a href="#需求7：" class="headerlink" title="需求7："></a>需求7：</h3><h4 id="统计出动词形态统一后的文件中出现的单词频率"><a href="#统计出动词形态统一后的文件中出现的单词频率" class="headerlink" title="统计出动词形态统一后的文件中出现的单词频率"></a>统计出动词形态统一后的文件中出现的单词频率</h4><p><strong>命令行参数</strong>要求：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wf.exe -v &lt;verb file&gt;</span><br></pre></td></tr></table></figure>
<h2 id="3，解题思路"><a href="#3，解题思路" class="headerlink" title="3，解题思路"></a>3，解题思路</h2><p>  该项目要求对英文文件中的<strong>字母单词</strong>等信息进行统计，而<strong>python</strong>对于文件处理支持的函数较多，故我决定使用<strong>python</strong>作为选择的编程语言。</p>
<h4 id="1-预处理："><a href="#1-预处理：" class="headerlink" title="1. 预处理："></a>1. 预处理：</h4><p>   将文件的字母全部转换成<strong>小写</strong>形式，并<strong>消除</strong>所有标点符号。</p>
<h4 id="2-对于需求一-统计出某个英文文本文件中的26个字母出现的频率-："><a href="#2-对于需求一-统计出某个英文文本文件中的26个字母出现的频率-：" class="headerlink" title="2. 对于需求一(统计出某个英文文本文件中的26个字母出现的频率)："></a>2. 对于需求一(统计出某个英文文本文件中的26个字母出现的频率)：</h4><p>   先判断文件是否<strong>存在</strong>，若不存在则报错，若存在则读取文件并对文件进行<strong>预处理</strong>，对文件进行遍历，将出现的所有字母存入字典中，并对字典进行排序，先按<strong>出现次数</strong>排序，若出现次数相同则按<strong>字典字母</strong>顺序排序。</p>
<h4 id="3-对于需求二-统计出某个英文文本文件中的所有不重复的单词-："><a href="#3-对于需求二-统计出某个英文文本文件中的所有不重复的单词-：" class="headerlink" title="3. 对于需求二(统计出某个英文文本文件中的所有不重复的单词)："></a>3. 对于需求二(统计出某个英文文本文件中的所有不重复的单词)：</h4><p>   先判断文件是否<strong>存在</strong>，若不存在则报错，若存在则读取文件并对文件进行<strong>预处理</strong>，使用分词函数<strong>split()</strong> 对文件进行分词，然后判断其是否为单词，将出现的所有单词存入字典中，并对字典进行排序，先按<strong>出现次数</strong>排序，若出现次数相同则按<strong>字典字母</strong>顺序排序。</p>
<h4 id="4-对于需求三-统计出指定文件目录下所有文件各自的所有不重复的单词-："><a href="#4-对于需求三-统计出指定文件目录下所有文件各自的所有不重复的单词-：" class="headerlink" title="4. 对于需求三(统计出指定文件目录下所有文件各自的所有不重复的单词)："></a>4. 对于需求三(统计出指定文件目录下所有文件各自的所有不重复的单词)：</h4><p>   先判断目录是否存在，若不存在则报错，若存在：<br>   若参数不包含 <strong>-s</strong>，则先<strong>遍历</strong>目录，找到所有文本文件的<strong>路径名</strong>，再对每个文本文件执行<strong>需求二</strong>需要的操作；<br>   若参数包含 <strong>-s</strong>，则<strong>递归遍历</strong>目录中所有文件，找到所有的文本文件的<strong>路径名</strong>，再对所有的文本文件执行<strong>需求二</strong>需要的操作。</p>
<h4 id="5-对于需求四-统计出文件中出现次数最多的前n个单词-："><a href="#5-对于需求四-统计出文件中出现次数最多的前n个单词-：" class="headerlink" title="5. 对于需求四(统计出文件中出现次数最多的前n个单词)："></a>5. 对于需求四(统计出文件中出现次数最多的前n个单词)：</h4><p>   在需求二的基础上对输出进行限制：<br>   若”-n”参数后<strong>无参数</strong>，则正常执行需求二；<br>   若”-n”参数后<strong>有参数</strong>，则输出指定数量的单词。</p>
<h4 id="6-对于需求五-统计出文件中出现非停用词的单词频率-："><a href="#6-对于需求五-统计出文件中出现非停用词的单词频率-：" class="headerlink" title="6. 对于需求五(统计出文件中出现非停用词的单词频率)："></a>6. 对于需求五(统计出文件中出现非停用词的单词频率)：</h4><p>   先判断文本文件和停用词文件是否<strong>存在</strong>，若不存在则报错，若存在则读取文本文件并进行<strong>预处理</strong>，使用分词函数<strong>split()</strong> 对文本文件进行分词，然后判断其是否为停用单词，将出现的所有非停用单词存入字典中，并对字典进行排序，先按<strong>出现次数</strong>排序，若出现次数相同则按<strong>字典字母</strong>顺序排序。</p>
<h4 id="7-对于需求六-统计出文件中出现指定单词个数的短语频率-："><a href="#7-对于需求六-统计出文件中出现指定单词个数的短语频率-：" class="headerlink" title="7. 对于需求六(统计出文件中出现指定单词个数的短语频率)："></a>7. 对于需求六(统计出文件中出现指定单词个数的短语频率)：</h4><p>   先判断文件是否<strong>存在</strong>，若不存在则报错，若存在则读取文件并对文件进行<strong>特殊预处理</strong>，即将所有标点符号都转换成符号”_” ,再使用<strong>分词函数”split()”</strong> 以此分词得到短语串，在使用<strong>去空格函数”strip()”</strong>  将短语串两端的空格去掉，再判断其是否为短语，将出现的所有短语存入字典中，并对字典进行排序，先按<strong>出现次数</strong>排序，若出现次数相同则按<strong>字典字母</strong>顺序排序，再将满足要求单词数量的短语输出。</p>
<h4 id="8-对于需求七-统计出动词形态统一后的文件中出现的单词频率-："><a href="#8-对于需求七-统计出动词形态统一后的文件中出现的单词频率-：" class="headerlink" title="8. 对于需求七(统计出动词形态统一后的文件中出现的单词频率)："></a>8. 对于需求七(统计出动词形态统一后的文件中出现的单词频率)：</h4><p>   先判断文本文件和动词文件是否<strong>存在</strong>，若不存在则报错，若存在则读取动词文本文件并进行<strong>预处理</strong>，使用分词函数<strong>split()</strong> 对文本文件进行分词，将其每一行的单词放入一个列表，然后读取文本文件进行<strong>预处理</strong>，使用replace()函数将动词转换成相应的原形，使用分词函数<strong>split()</strong> 对文本文件进行分词，将出现的所有单词存入字典中，并对字典进行排序，先按<strong>出现次数</strong>排序，若出现次数相同则按<strong>字典字母</strong>顺序排序。</p>
<h2 id="4，实现过程"><a href="#4，实现过程" class="headerlink" title="4，实现过程"></a>4，实现过程</h2><h3 id="4-1-函数列表："><a href="#4-1-函数列表：" class="headerlink" title="4.1 函数列表："></a>4.1 函数列表：</h3><h5 id="GetText-FilePath-：获得预处理后的文档内容"><a href="#GetText-FilePath-：获得预处理后的文档内容" class="headerlink" title="GetText(FilePath)：获得预处理后的文档内容"></a>GetText(FilePath)：获得预处理后的文档内容</h5><h5 id="IsWord-JudgedWord-：判断一个词是不是符合定义的单词"><a href="#IsWord-JudgedWord-：判断一个词是不是符合定义的单词" class="headerlink" title="IsWord(JudgedWord)：判断一个词是不是符合定义的单词"></a>IsWord(JudgedWord)：判断一个词是不是符合定义的单词</h5><h5 id="IsPhrase-JudgedPhrase-判断一个”短语”是不是符合定义的短语"><a href="#IsPhrase-JudgedPhrase-判断一个”短语”是不是符合定义的短语" class="headerlink" title="IsPhrase(JudgedPhrase): 判断一个”短语”是不是符合定义的短语"></a>IsPhrase(JudgedPhrase): 判断一个”短语”是不是符合定义的短语</h5><h5 id="GetVerbList-FilePath-：得到动词文本中的动词列表"><a href="#GetVerbList-FilePath-：得到动词文本中的动词列表" class="headerlink" title="GetVerbList(FilePath)：得到动词文本中的动词列表"></a>GetVerbList(FilePath)：得到动词文本中的动词列表</h5><h5 id="LetterFrequence-FilePath-：统计文档中的字母频率"><a href="#LetterFrequence-FilePath-：统计文档中的字母频率" class="headerlink" title="LetterFrequence(FilePath)：统计文档中的字母频率"></a>LetterFrequence(FilePath)：统计文档中的字母频率</h5><h5 id="WordFrequence-FilePath-nFlag-：统计文档中的单词频率"><a href="#WordFrequence-FilePath-nFlag-：统计文档中的单词频率" class="headerlink" title="WordFrequence(FilePath, nFlag)：统计文档中的单词频率"></a>WordFrequence(FilePath, nFlag)：统计文档中的单词频率</h5><h5 id="NotStopWordFrequence-StopFilePath-FilePath-nFlag-：统计文档中的非停用词的单词频率"><a href="#NotStopWordFrequence-StopFilePath-FilePath-nFlag-：统计文档中的非停用词的单词频率" class="headerlink" title="NotStopWordFrequence(StopFilePath, FilePath, nFlag)：统计文档中的非停用词的单词频率"></a>NotStopWordFrequence(StopFilePath, FilePath, nFlag)：统计文档中的非停用词的单词频率</h5><h5 id="PhraseFrequence-FilePath-num-：统计出文件中出现指定单词个数的短语频率"><a href="#PhraseFrequence-FilePath-num-：统计出文件中出现指定单词个数的短语频率" class="headerlink" title="PhraseFrequence(FilePath, num)：统计出文件中出现指定单词个数的短语频率"></a>PhraseFrequence(FilePath, num)：统计出文件中出现指定单词个数的短语频率</h5><h5 id="DirFileWF-DirPath-sFlag-nFlag-递归-统计出目录下各文本文件中的所有不重复的单词频率"><a href="#DirFileWF-DirPath-sFlag-nFlag-递归-统计出目录下各文本文件中的所有不重复的单词频率" class="headerlink" title="DirFileWF(DirPath, sFlag, nFlag): [递归]统计出目录下各文本文件中的所有不重复的单词频率"></a>DirFileWF(DirPath, sFlag, nFlag): [递归]统计出目录下各文本文件中的所有不重复的单词频率</h5><h5 id="main-：接受命令行参数并分别调用相应函数"><a href="#main-：接受命令行参数并分别调用相应函数" class="headerlink" title="main()：接受命令行参数并分别调用相应函数"></a>main()：接受命令行参数并分别调用相应函数</h5><h3 id="4-2-代码展示及解释："><a href="#4-2-代码展示及解释：" class="headerlink" title="4.2 代码展示及解释："></a>4.2 代码展示及解释：</h3><h4 id="GetText-FilePath-对文档进行预处理"><a href="#GetText-FilePath-对文档进行预处理" class="headerlink" title="GetText(FilePath): 对文档进行预处理"></a><strong>GetText(FilePath): 对文档进行预处理</strong></h4><p>传入参数为文件路径，先判断文件是否存在，若不存在则输出<code>File Not Exist!</code>错误信息提示；若存在则将文件的字母全部转换成小写形式，并消除所有标点符号。若<code>vFlag</code>为真，则转换动词的形式，最后返回文本处理后的结果。<br>其<strong>函数调用</strong>有：<code>GetVerbList()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">GetText</span>(<span class="params">FilePath</span>):</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(FilePath):   <span class="comment">#判断文件是否存在</span></span><br><span class="line">        txtContent = <span class="built_in">open</span>(FilePath, <span class="string">&quot;r&quot;</span>, errors = <span class="string">&#x27;ignore&#x27;</span>).read()  <span class="comment">#打开文件</span></span><br><span class="line">        txtContent = txtContent.lower()   <span class="comment">#转小写</span></span><br><span class="line">        <span class="keyword">for</span> char <span class="keyword">in</span> nonWordChar:</span><br><span class="line">            txtContent = txtContent.replace(char, <span class="string">&quot; &quot;</span>)  <span class="comment">#转换成空格</span></span><br><span class="line">        <span class="keyword">if</span> vFlag:</span><br><span class="line">            VerbList = GetVerbList(vPathFile)  <span class="comment">#获取动词列表</span></span><br><span class="line">            <span class="keyword">for</span> VList <span class="keyword">in</span> VerbList:</span><br><span class="line">                <span class="keyword">for</span> ch <span class="keyword">in</span> VList:</span><br><span class="line">                    txtContent = txtContent.replace(ch, VList[<span class="number">0</span>])  <span class="comment">#将动词换为原型</span></span><br><span class="line">        <span class="keyword">return</span> txtContent</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">&quot;File Not Exist!&quot;</span>)</span><br><span class="line">        sys.exit()</span><br></pre></td></tr></table></figure>
<h4 id="IsWord-JudgedWord-：判断一个词是不是符合定义的单词-1"><a href="#IsWord-JudgedWord-：判断一个词是不是符合定义的单词-1" class="headerlink" title="IsWord(JudgedWord)：判断一个词是不是符合定义的单词"></a><strong>IsWord(JudgedWord)：判断一个词是不是符合定义的单词</strong></h4><p>传入参数为一个词，首先判断其是否为空，若为空返回<code>False</code>;再判断是否以字母开头，若不为返回<code>False</code>；最后判断其后的是否为字母数字字符，若不为则返回<code>False</code>。上述条件均满足则返回<code>True</code>。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">IsWord</span>(<span class="params">JudgedWord</span>):</span></span><br><span class="line">    <span class="keyword">if</span> JudgedWord == <span class="string">&quot;&quot;</span>:   <span class="comment"># 非空</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">elif</span> JudgedWord[<span class="number">0</span>] <span class="keyword">not</span> <span class="keyword">in</span> legalLetterList: <span class="comment"># 以字母开头</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="keyword">for</span> char <span class="keyword">in</span> JudgedWord:   </span><br><span class="line">            <span class="keyword">if</span> char <span class="keyword">not</span> <span class="keyword">in</span> legalWordList:   <span class="comment"># 由字母和数字组成</span></span><br><span class="line">                <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br></pre></td></tr></table></figure>
<h4 id="IsPhrase-JudgedPhrase-判断一个”短语”是不是符合定义的短语-1"><a href="#IsPhrase-JudgedPhrase-判断一个”短语”是不是符合定义的短语-1" class="headerlink" title="IsPhrase(JudgedPhrase): 判断一个”短语”是不是符合定义的短语"></a><strong>IsPhrase(JudgedPhrase): 判断一个”短语”是不是符合定义的短语</strong></h4><p>传入参数为一个”短语”，首先按空格分词，若分词后只有一个，则返回<code>False</code>;否则判断分词后的列表中是否均为单词，若不为返回<code>False</code>，否则返回<code>True</code>。<br>其<strong>函数调用</strong>有：<code>IsWord()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">IsPhrase</span>(<span class="params">JudgedPhrase</span>):</span></span><br><span class="line">    pList = JudgedPhrase.split(<span class="string">&quot; &quot;</span>)</span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(pList) == <span class="number">1</span>:   <span class="comment"># 两个或两个以上</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">for</span> word <span class="keyword">in</span> pList:</span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> IsWord(word):   <span class="comment"># 单词</span></span><br><span class="line">            <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br></pre></td></tr></table></figure>
<h4 id="GetVerbList-FilePath-：得到动词文本中的动词列表-1"><a href="#GetVerbList-FilePath-：得到动词文本中的动词列表-1" class="headerlink" title="GetVerbList(FilePath)：得到动词文本中的动词列表"></a><strong>GetVerbList(FilePath)：得到动词文本中的动词列表</strong></h4><p>传入参数为一个文本路径，首先判断文本是否存在，若不存在则输出<code>File Not Exist!</code>错误信息提示；若存在则先按<code>\n</code>一次分词，得到文本中的一行，然后使用<code>&quot; &quot;</code>二次分词，得到每一行的单词列表，最后返回为一个动词列表<code>vList</code>。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">GetVerbList</span>(<span class="params">FilePath</span>):</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(FilePath):</span><br><span class="line">        tContent = <span class="built_in">open</span>(FilePath, <span class="string">&quot;r&quot;</span>, errors = <span class="string">&#x27;ignore&#x27;</span>).read()  <span class="comment">#打开文件</span></span><br><span class="line">        tContent = tContent.lower()   <span class="comment">#转小写</span></span><br><span class="line">        vbList = tContent.split(<span class="string">&#x27;\n&#x27;</span>)   <span class="comment">#一次分词，按&#x27;\n&#x27;分词</span></span><br><span class="line">        vList = []</span><br><span class="line">        <span class="keyword">for</span> ch <span class="keyword">in</span> vbList:</span><br><span class="line">            vList.append(ch.split())    <span class="comment">#二次分词， 按&quot;&quot;分词</span></span><br><span class="line">        <span class="keyword">return</span> vList</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">&quot;File Not Exist!&quot;</span>)</span><br><span class="line">        sys.exit()</span><br></pre></td></tr></table></figure>
<h4 id="LetterFrequence-FilePath-：统计文档中的字母频率-1"><a href="#LetterFrequence-FilePath-：统计文档中的字母频率-1" class="headerlink" title="LetterFrequence(FilePath)：统计文档中的字母频率"></a><strong>LetterFrequence(FilePath)：统计文档中的字母频率</strong></h4><p>传入参数为一个文本路径，首先使用<code>GetText()</code>对文本进行预处理，得到处理后的文本内容。使用<code>count()</code>函数对文本中的字母进行统计，并存入字典中，最后按照频率、字典序对字典进行二级排序，输出文本中的字母频率。<br>其<strong>函数调用</strong>有：<code>GetText()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">LetterFrequence</span>(<span class="params">FilePath</span>):</span></span><br><span class="line">    content = GetText(FilePath)</span><br><span class="line">    print(<span class="string">&quot;In file &quot;</span> + FilePath + <span class="string">&quot;:&quot;</span>)</span><br><span class="line">    letterDic = <span class="built_in">dict</span>()</span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> ch <span class="keyword">in</span> legalLetterList:   <span class="comment">#对字母进行统计</span></span><br><span class="line">        letterDic[ch] = content.count(ch)</span><br><span class="line">        <span class="built_in">sum</span> += letterDic[ch]</span><br><span class="line">    <span class="keyword">for</span> ch, count <span class="keyword">in</span> <span class="built_in">sorted</span>(letterDic.items(), key= <span class="keyword">lambda</span> x:(-x[<span class="number">1</span>], x[<span class="number">0</span>])):  <span class="comment">#字典排序</span></span><br><span class="line">        <span class="keyword">if</span> count != <span class="number">0</span>:</span><br><span class="line">            letterFre = (count/<span class="built_in">sum</span>) * <span class="number">100</span>    <span class="comment">#计算频率</span></span><br><span class="line">            print(<span class="string">&#x27;Frequence of letter &#x27;</span> + ch + <span class="string">&#x27; is &#x27;</span> + <span class="string">&#x27;%.2f&#x27;</span> % letterFre + <span class="string">&quot;%&quot;</span> +<span class="string">&quot; (&quot;</span> + <span class="built_in">str</span>(count) + <span class="string">&quot;)&quot;</span>)  <span class="comment">#输出</span></span><br></pre></td></tr></table></figure>
<h4 id="WordFrequence-FilePath-nFlag-：统计文档中的单词频率-1"><a href="#WordFrequence-FilePath-nFlag-：统计文档中的单词频率-1" class="headerlink" title="WordFrequence(FilePath, nFlag)：统计文档中的单词频率"></a><strong>WordFrequence(FilePath, nFlag)：统计文档中的单词频率</strong></h4><p>传入参数为文本路径和<code>nFlag</code>，<code>nfalg</code>若 <code>&gt;0</code> 则包含对输出个数的限制，反之则无。首先使用<code>GetText()</code>对文本进行预处理，得到处理后的文本内容。使用<code>IsWord()</code>判断是否为单词，再使用<code>get()</code>函数对文本中的单词进行统计，并存入字典中，最后按照频率、字典序对字典进行二级排序，根据<code>nFlag</code>输出要求个数的文本中的单词频率。<br>其<strong>函数调用</strong>有：<code>GetText()</code>，<code>IsWord()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">WordFrequence</span>(<span class="params">FilePath, nFlag</span>):</span> </span><br><span class="line">    content = GetText(FilePath)</span><br><span class="line">    print(<span class="string">&quot;In file &quot;</span> + FilePath + <span class="string">&quot;:&quot;</span>)</span><br><span class="line">    words = content.split()   <span class="comment"># 分成词的形式</span></span><br><span class="line">    wordDic = <span class="built_in">dict</span>()</span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">        <span class="keyword">if</span> IsWord(word):     <span class="comment"># 判断是否是单词      </span></span><br><span class="line">            wordDic[word] = wordDic.get(word, <span class="number">0</span>) + <span class="number">1</span>  <span class="comment"># 对单词进行统计</span></span><br><span class="line">            <span class="built_in">sum</span> += <span class="number">1</span></span><br><span class="line">    print(<span class="string">&#x27;Words sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">len</span>(wordDic)) + <span class="string">&#x27;  total sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">sum</span>))</span><br><span class="line">    <span class="keyword">if</span> nFlag:</span><br><span class="line">        <span class="keyword">if</span> nFlag == <span class="string">&quot;1&quot;</span>:</span><br><span class="line">            print(<span class="string">&quot;The top &quot;</span> + nFlag + <span class="string">&quot; word:&quot;</span> )</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            print(<span class="string">&quot;The top &quot;</span> + nFlag + <span class="string">&quot; words:&quot;</span> )</span><br><span class="line">    nCount = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> word, count <span class="keyword">in</span> <span class="built_in">sorted</span>(wordDic.items(), key= <span class="keyword">lambda</span> x:(-x[<span class="number">1</span>], x[<span class="number">0</span>])):  <span class="comment">#字典排序</span></span><br><span class="line">        nCount += <span class="number">1</span></span><br><span class="line">        wordFre = (count/<span class="built_in">sum</span>) * <span class="number">100</span>    <span class="comment">#计算频率</span></span><br><span class="line">        print(<span class="string">&#x27;Frequence of word &#x27;</span> + <span class="string">&#x27;\&quot;&#x27;</span> + word + <span class="string">&#x27;\&quot;&#x27;</span>+<span class="string">&#x27; is &#x27;</span> + <span class="string">&#x27;%.2f&#x27;</span> % wordFre + <span class="string">&quot;%&quot;</span> + <span class="string">&quot; (&quot;</span> + <span class="built_in">str</span>(count) + <span class="string">&quot;)&quot;</span>)  <span class="comment">#输出</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">str</span>(nCount) == nFlag:</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span></span><br></pre></td></tr></table></figure>
<h4 id="NotStopWordFrequence-StopFilePath-FilePath-nFlag-：统计文档中的非停用词的单词频率-1"><a href="#NotStopWordFrequence-StopFilePath-FilePath-nFlag-：统计文档中的非停用词的单词频率-1" class="headerlink" title="NotStopWordFrequence(StopFilePath, FilePath, nFlag)：统计文档中的非停用词的单词频率"></a><strong>NotStopWordFrequence(StopFilePath, FilePath, nFlag)：统计文档中的非停用词的单词频率</strong></h4><p>传入参数为停用词文本路径，文本路径和<code>nFlag</code>，<code>nfalg</code>若 <code>&gt;0</code> 则包含对输出个数的限制，反之则无。首先使用<code>GetText()</code>对通用词文本和文本进行预处理，得到处理后的文本内容。使用<code>split()</code>对文本内容进行分词，判断其是否为单词，若为再判断是否为停用词，若不为则使用<code>get()</code>函数对文本中的单词进行统计，并存入字典中，最后按照频率、字典序对字典进行二级排序，根据<code>nFlag</code>输出要求个数的文本中的单词频率。<br>其<strong>函数调用</strong>有：<code>GetText()</code>，<code>IsWord()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">NotStopWordFrequence</span>(<span class="params">StopFilePath, FilePath, nFlag</span>):</span></span><br><span class="line">    stopContent = GetText(StopFilePath)</span><br><span class="line">    content = GetText(FilePath)</span><br><span class="line">    print(<span class="string">&quot;In file &quot;</span> + FilePath + <span class="string">&quot;:&quot;</span>)</span><br><span class="line">    stopWords = stopContent.split()</span><br><span class="line">    words = content.split()</span><br><span class="line">    wordDic = <span class="built_in">dict</span>()</span><br><span class="line">    <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> word <span class="keyword">in</span> words:</span><br><span class="line">        <span class="keyword">if</span> IsWord(word):      <span class="comment"># 判断是否是单词 </span></span><br><span class="line">            <span class="keyword">if</span> word <span class="keyword">not</span> <span class="keyword">in</span> stopWords:   <span class="comment"># 判断是否是停用词</span></span><br><span class="line">                wordDic[word] = wordDic.get(word, <span class="number">0</span>) + <span class="number">1</span></span><br><span class="line">                <span class="built_in">sum</span> += <span class="number">1</span></span><br><span class="line">    print(<span class="string">&#x27;Not stop Words sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">len</span>(wordDic)) + <span class="string">&#x27;  total sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">sum</span>))</span><br><span class="line">    <span class="keyword">if</span> nFlag:</span><br><span class="line">        <span class="keyword">if</span> nFlag == <span class="string">&quot;1&quot;</span>:</span><br><span class="line">            print(<span class="string">&quot;The top &quot;</span> + nFlag + <span class="string">&quot; not stop word:&quot;</span> )</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            print(<span class="string">&quot;The top &quot;</span> + nFlag + <span class="string">&quot; not stop words:&quot;</span> )</span><br><span class="line">    nCount = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> word, count <span class="keyword">in</span> <span class="built_in">sorted</span>(wordDic.items(), key= <span class="keyword">lambda</span> x:(-x[<span class="number">1</span>], x[<span class="number">0</span>])):  <span class="comment">#字典排序</span></span><br><span class="line">        nCount += <span class="number">1</span></span><br><span class="line">        wordFre = (count/<span class="built_in">sum</span>) * <span class="number">100</span>    <span class="comment">#计算频率</span></span><br><span class="line">        print(<span class="string">&#x27;Frequence of word &#x27;</span> + <span class="string">&#x27;\&quot;&#x27;</span> + word + <span class="string">&#x27;\&quot;&#x27;</span>+<span class="string">&#x27; is &#x27;</span> + <span class="string">&#x27;%.2f&#x27;</span> % wordFre + <span class="string">&quot;%&quot;</span>  + <span class="string">&quot; (&quot;</span> + <span class="built_in">str</span>(count) + <span class="string">&quot;)&quot;</span>)  <span class="comment">#输出</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">str</span>(nCount) == nFlag:</span><br><span class="line">            <span class="keyword">return</span> <span class="number">0</span></span><br></pre></td></tr></table></figure>
<h4 id="PhraseFrequence-FilePath-num-：统计出文件中出现指定单词个数的短语频率-1"><a href="#PhraseFrequence-FilePath-num-：统计出文件中出现指定单词个数的短语频率-1" class="headerlink" title="PhraseFrequence(FilePath, num)：统计出文件中出现指定单词个数的短语频率"></a><strong>PhraseFrequence(FilePath, num)：统计出文件中出现指定单词个数的短语频率</strong></h4><p>传入参数为文本路径和<code>num</code>。首先使用对文本进行预处理(包含-v的动词处理)，得到处理后的文本内容。将所有标点符号都转换成符号”_” ,再使用<code>split()</code> 以此分词得到短语串，在使用<code>strip()</code>将短语串两端的空格去掉。使用<code>IsPhrase()</code>判断是否为短语，再使用<code>get()</code>函数对文本中的短语进行统计，并存入字典中，最后按照频率、字典序对字典进行二级排序，根据<code>num</code>输出文本中要求单词个数的短语频率。<br>其<strong>函数调用</strong>有：<code>GetVerbList()</code>，<code>IsPhrase()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">PhraseFrequence</span>(<span class="params">FilePath, num</span>):</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(FilePath):   <span class="comment">#判断文件是否存在</span></span><br><span class="line">        print(<span class="string">&quot;In file &quot;</span> + FilePath + <span class="string">&quot;:&quot;</span>)</span><br><span class="line">        txtContent = <span class="built_in">open</span>(FilePath, <span class="string">&quot;r&quot;</span>, errors = <span class="string">&#x27;ignore&#x27;</span>).read()  <span class="comment">#打开文件</span></span><br><span class="line">        txtContent = txtContent.lower()   <span class="comment">#转小写</span></span><br><span class="line">        <span class="keyword">if</span> vFlag:</span><br><span class="line">            VerbList = GetVerbList(vPathFile)</span><br><span class="line">            <span class="keyword">for</span> VList <span class="keyword">in</span> VerbList:</span><br><span class="line">                <span class="keyword">for</span> ch <span class="keyword">in</span> VList:</span><br><span class="line">                    txtContent = txtContent.replace(ch, VList[<span class="number">0</span>])  <span class="comment">#将动词换为原型</span></span><br><span class="line">        <span class="keyword">for</span> char <span class="keyword">in</span> nonWordChar:</span><br><span class="line">            txtContent = txtContent.replace(char, <span class="string">&quot;_&quot;</span>)    <span class="comment">#将非空格用&quot;_&quot;替换 </span></span><br><span class="line">        txtContent = txtContent.replace(<span class="string">&#x27;\n&#x27;</span>, <span class="string">&quot; &quot;</span>)    <span class="comment">#将回车符转换成空格    </span></span><br><span class="line">        phraseList = txtContent.split(<span class="string">&quot;_&quot;</span>)</span><br><span class="line">        phraseDic = <span class="built_in">dict</span>()</span><br><span class="line">        <span class="built_in">sum</span> = <span class="number">0</span></span><br><span class="line">        existFlag = <span class="literal">False</span></span><br><span class="line">        <span class="keyword">for</span> phrase <span class="keyword">in</span> phraseList:     </span><br><span class="line">            phrase = phrase.strip()</span><br><span class="line">            <span class="keyword">if</span> IsPhrase(phrase):</span><br><span class="line">                phraseDic[phrase] = phraseDic.get(phrase, <span class="number">0</span>) + <span class="number">1</span>  <span class="comment"># 对短语进行统计</span></span><br><span class="line">                <span class="built_in">sum</span> += <span class="number">1</span></span><br><span class="line">        print(<span class="string">&#x27;Phrases sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">len</span>(phraseDic)) + <span class="string">&#x27;  total sum: &#x27;</span> + <span class="built_in">str</span>(<span class="built_in">sum</span>))</span><br><span class="line">        <span class="keyword">for</span> phrase, count <span class="keyword">in</span> <span class="built_in">sorted</span>(phraseDic.items(), key= <span class="keyword">lambda</span> x:(-x[<span class="number">1</span>], x[<span class="number">0</span>])):  <span class="comment">#字典排序</span></span><br><span class="line">            phraseFre = (count/<span class="built_in">sum</span>) * <span class="number">100</span>    <span class="comment">#计算频率</span></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">str</span>(<span class="built_in">len</span>(phrase.split())) == num:</span><br><span class="line">                print(<span class="string">&#x27;Frequence of phrase &#x27;</span> + <span class="string">&#x27;\&quot;&#x27;</span> + phrase + <span class="string">&#x27;\&quot;&#x27;</span>+<span class="string">&#x27; is &#x27;</span> + <span class="string">&#x27;%.2f&#x27;</span> % phraseFre + <span class="string">&quot;%&quot;</span> )  <span class="comment">#输出</span></span><br><span class="line">                existFlag = <span class="literal">True</span></span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> existFlag:</span><br><span class="line">            print(<span class="string">&quot;There is no phrase that satisfies the condition!&quot;</span>) </span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">&quot;File Not Exist!&quot;</span>)</span><br><span class="line">        sys.exit()</span><br></pre></td></tr></table></figure>
<h4 id="DirFileWF-DirPath-sFlag-nFlag-递归-统计出目录下各文本文件中的所有不重复的单词频率-1"><a href="#DirFileWF-DirPath-sFlag-nFlag-递归-统计出目录下各文本文件中的所有不重复的单词频率-1" class="headerlink" title="DirFileWF(DirPath, sFlag, nFlag): [递归]统计出目录下各文本文件中的所有不重复的单词频率"></a><strong>DirFileWF(DirPath, sFlag, nFlag): [递归]统计出目录下各文本文件中的所有不重复的单词频率</strong></h4><p>传入参数为目录路径，<code>sFlag</code>和<code>nFlag</code>，<code>nfalg</code>若 <code>&gt;0</code> 则包含对输出个数的限制，反之则无。首先判断目录文件是否存在，若不存在输出”Dir File Not Exist!”错误信息提示，若存在则判断<code>sFlag</code>是否为真，若为真则递归遍历该目录，对每个文件执行<code>WordFrequence()</code>操作，否则只遍历当前目录的文件，执行<code>WordFrequence()</code>操作<br>其<strong>函数调用</strong>有：<code>WordFrequence()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">DirFileWF</span>(<span class="params">DirPath, sFlag, nFlag</span>):</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(DirPath):</span><br><span class="line">        <span class="keyword">for</span> root, dirName, fileName <span class="keyword">in</span> os.walk(DirPath):   <span class="comment"># 递归遍历目录</span></span><br><span class="line">            <span class="keyword">if</span> sFlag:   <span class="comment"># 若参数含-s</span></span><br><span class="line">                <span class="keyword">if</span> fileName != []:</span><br><span class="line">                    <span class="keyword">for</span> fName <span class="keyword">in</span> fileName:   <span class="comment"># 得到文件路径名</span></span><br><span class="line">                        filePath = root + <span class="string">&quot;\\&quot;</span> + fName</span><br><span class="line">                        WordFrequence(filePath, nFlag)</span><br><span class="line">                        print(<span class="string">&quot;&quot;</span>)</span><br><span class="line">            <span class="keyword">else</span>:                     <span class="comment"># 若参数无-s</span></span><br><span class="line">                <span class="keyword">if</span> root == DirPath:   <span class="comment"># 只需遍历当前目录</span></span><br><span class="line">                    <span class="keyword">if</span> fileName != []:</span><br><span class="line">                        <span class="keyword">for</span> fName <span class="keyword">in</span> fileName:   <span class="comment"># 得到文件路径名</span></span><br><span class="line">                            filePath = root + <span class="string">&quot;\\&quot;</span> + fName</span><br><span class="line">                            WordFrequence(filePath, nFlag)</span><br><span class="line">                            print(<span class="string">&quot;&quot;</span>)</span><br><span class="line">                        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">&quot;Dir File Not Exist!&quot;</span>)</span><br><span class="line">        sys.exit()</span><br></pre></td></tr></table></figure>
<h4 id="main-：接受命令行参数并分别调用相应函数-1"><a href="#main-：接受命令行参数并分别调用相应函数-1" class="headerlink" title="main()：接受命令行参数并分别调用相应函数"></a><strong>main()：接受命令行参数并分别调用相应函数</strong></h4><p>对命令行参数进行归类，并正确调用相应的函数，若命令行有误，则输出相应错误信息。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">    <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &lt;= <span class="number">2</span> <span class="keyword">or</span> <span class="built_in">len</span>(sys.argv) &gt; <span class="number">9</span>:</span><br><span class="line">        print(<span class="string">&quot;Parameter Error!&quot;</span>)</span><br><span class="line">        sys.exit()</span><br><span class="line">    <span class="comment"># wf.exe -v &lt;verb file&gt;  将文件动词形态统一后再统计</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(sys.argv)):</span><br><span class="line">        <span class="keyword">if</span> sys.argv[i] == <span class="string">&quot;-v&quot;</span>:</span><br><span class="line">            <span class="keyword">global</span> vFlag</span><br><span class="line">            vFlag = <span class="literal">True</span></span><br><span class="line">            <span class="keyword">global</span> vPathFile</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &gt; i+<span class="number">1</span>:</span><br><span class="line">                vPathFile = sys.argv[i+<span class="number">1</span>]</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                print(<span class="string">&quot;Parameter Error!&quot;</span>)</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">    <span class="comment"># wf.exe -c &lt;file name&gt;  统计出某个英文文本文件中的26个字母出现的频率</span></span><br><span class="line">    <span class="keyword">if</span> sys.argv[<span class="number">1</span>] == <span class="string">&quot;-c&quot;</span>:    </span><br><span class="line">        LetterFrequence(sys.argv[<span class="number">2</span>])</span><br><span class="line">    <span class="comment"># wf.exe -f &lt;file name&gt;  统计出某个英文文本文件中的所有不重复的单词频率 </span></span><br><span class="line">    <span class="comment"># wf.exe -f &lt;file name&gt; -n [&lt;int&gt;]  统计出文件中出现次数最多的前n个单词的单词频率</span></span><br><span class="line">    <span class="keyword">elif</span> sys.argv[<span class="number">1</span>] == <span class="string">&quot;-f&quot;</span>:</span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &gt;= <span class="number">5</span>:</span><br><span class="line">            <span class="keyword">if</span> sys.argv[<span class="number">3</span>] == <span class="string">&quot;-n&quot;</span> <span class="keyword">and</span> sys.argv[<span class="number">4</span>][<span class="number">0</span>] != <span class="string">&quot;-&quot;</span>:</span><br><span class="line">                WordFrequence(sys.argv[<span class="number">2</span>], sys.argv[<span class="number">4</span>])</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                WordFrequence(sys.argv[<span class="number">2</span>], <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            WordFrequence(sys.argv[<span class="number">2</span>], <span class="number">0</span>)</span><br><span class="line">    <span class="comment"># wf.exe -d [-s] &lt;directory&gt;  [递归]统计出目录下各文本文件中的所有不重复的单词频率</span></span><br><span class="line">    <span class="comment"># wf.exe -d [-s] &lt;directory&gt; -n [&lt;int&gt;] [递归]统计出目录下各文本文件中出现次数最多的前n个单词的单词频率</span></span><br><span class="line">    <span class="keyword">elif</span> sys.argv[<span class="number">1</span>] == <span class="string">&quot;-d&quot;</span>:</span><br><span class="line">        <span class="keyword">if</span> sys.argv[<span class="number">2</span>] == <span class="string">&quot;-s&quot;</span>:</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &gt;= <span class="number">6</span> <span class="keyword">and</span> sys.argv[<span class="number">4</span>] == <span class="string">&quot;-n&quot;</span> <span class="keyword">and</span> sys.argv[<span class="number">5</span>][<span class="number">0</span>] != <span class="string">&quot;-&quot;</span>:</span><br><span class="line">                DirFileWF(sys.argv[<span class="number">3</span>], <span class="literal">True</span>, sys.argv[<span class="number">5</span>])</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                DirFileWF(sys.argv[<span class="number">3</span>], <span class="literal">True</span>, <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &gt;= <span class="number">5</span> <span class="keyword">and</span> sys.argv[<span class="number">3</span>] == <span class="string">&quot;-n&quot;</span> <span class="keyword">and</span> sys.argv[<span class="number">4</span>][<span class="number">0</span>] != <span class="string">&quot;-&quot;</span>:</span><br><span class="line">                DirFileWF(sys.argv[<span class="number">2</span>], <span class="literal">False</span>, sys.argv[<span class="number">4</span>])</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                DirFileWF(sys.argv[<span class="number">2</span>], <span class="literal">False</span>, <span class="number">0</span>)</span><br><span class="line">    <span class="comment"># wf.exe -x &lt;stopwordfile&gt; -f &lt;file&gt;  统计出某个英文文本文件中的不在停用表中的所有不重复的单词频率</span></span><br><span class="line">    <span class="comment"># wf.exe -x &lt;stopwordfile&gt; -f &lt;file&gt; -n [&lt;int&gt;] 统计出某个英文文本文件中出现次数最多的前n个单词的单词频率 </span></span><br><span class="line">    <span class="keyword">elif</span> sys.argv[<span class="number">1</span>] == <span class="string">&quot;-x&quot;</span> <span class="keyword">and</span> sys.argv[<span class="number">3</span>] == <span class="string">&quot;-f&quot;</span>:</span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">len</span>(sys.argv) &gt;= <span class="number">7</span> <span class="keyword">and</span> sys.argv[<span class="number">5</span>] == <span class="string">&quot;-n&quot;</span> <span class="keyword">and</span> sys.argv[<span class="number">6</span>][<span class="number">0</span>] != <span class="string">&quot;-&quot;</span>:</span><br><span class="line">            NotStopWordFrequence(sys.argv[<span class="number">2</span>], sys.argv[<span class="number">4</span>], sys.argv[<span class="number">6</span>])</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            NotStopWordFrequence(sys.argv[<span class="number">2</span>], sys.argv[<span class="number">4</span>], <span class="number">0</span>)</span><br><span class="line">    <span class="comment"># wf.exe &lt;file name&gt; -p &lt;int&gt; 统计出文件中出现指定单词个数的短语频率</span></span><br><span class="line">    <span class="keyword">elif</span> sys.argv[<span class="number">2</span>] == <span class="string">&quot;-p&quot;</span>:</span><br><span class="line">        PhraseFrequence(sys.argv[<span class="number">1</span>], sys.argv[<span class="number">3</span>])</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">&quot;Parameter Error!&quot;</span>)    </span><br></pre></td></tr></table></figure>
<h2 id="5，软件测试"><a href="#5，软件测试" class="headerlink" title="5，软件测试"></a>5，软件测试</h2><h3 id="5-1-单元测试设计："><a href="#5-1-单元测试设计：" class="headerlink" title="5.1 单元测试设计："></a>5.1 单元测试设计：</h3><p> 使用<strong>python</strong>提供的<strong>pytest</strong>对WF.py中的<strong>基本函数</strong>进行测试(如IsWord(), IsPrase())，并编写相应的<strong>单元测试用例文件</strong>，有test_IsWord.py, test_IsPhrase.py，下面以<strong>test_IsPhrase</strong>举例说明：<br> <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> <span class="keyword">import</span> pytest</span><br><span class="line"><span class="keyword">from</span> WF <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test_null</span>():</span></span><br><span class="line">    phrase = <span class="string">&quot;&quot;</span></span><br><span class="line">    <span class="keyword">assert</span> IsPhrase(phrase) == <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test_one</span>():</span></span><br><span class="line">    phrase = <span class="string">&quot;hello&quot;</span></span><br><span class="line">    <span class="keyword">assert</span> IsPhrase(phrase) == <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test_two</span>():</span></span><br><span class="line">    phrase = <span class="string">&quot;hello world&quot;</span></span><br><span class="line">    <span class="keyword">assert</span> IsPhrase(phrase) == <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test_three</span>():</span></span><br><span class="line">    phrase = <span class="string">&quot;hello world good123&quot;</span></span><br><span class="line">    <span class="keyword">assert</span> IsPhrase(phrase) == <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test_four</span>():</span></span><br><span class="line">    phrase = <span class="string">&quot;hello world 123goood&quot;</span></span><br><span class="line">    <span class="keyword">assert</span> IsPhrase(phrase) == <span class="literal">False</span></span><br></pre></td></tr></table></figure><br> 将判断一个词是否为短语的各种情况分别测试，此时传入的JudgedPhrase为去除首尾空格的字符串，有为空，单个单词，两个单词，由非单词组成的“短语”，三个单词的情况，首先人为设定断言assert结果，测试结果如下：</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"> &#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D; test session starts &#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br><span class="line">platform win32 -- Python 3.7.0, pytest-6.2.2, py-1.10.0, pluggy-0.13.1</span><br><span class="line">rootdir: e:\WF</span><br><span class="line">plugins: cov-2.10.1</span><br><span class="line">collected 5 items</span><br><span class="line"></span><br><span class="line">test_IsPhrase.py .....                                                   [100%]</span><br><span class="line"></span><br><span class="line">- generated xml file: C:\Users\Lenovo\AppData\Local\Temp\tmp-149886dRSrLhAkTtl.xml -</span><br><span class="line">&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D; 5 passed in 0.06s &#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;&#x3D;</span><br></pre></td></tr></table></figure>
<p>由此可见，该文件中的5个小测试用例均已通过。</p>
<h3 id="5-2-功能测试设计："><a href="#5-2-功能测试设计：" class="headerlink" title="5.2 功能测试设计："></a>5.2 功能测试设计：</h3><h4 id="5-2-1-字母频率统计"><a href="#5-2-1-字母频率统计" class="headerlink" title="5.2.1 字母频率统计"></a>5.2.1 字母频率统计</h4><p>使用编写的简单测试文本test_letter.txt进行测试，其内容如下：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Youth is not a time of life; </span><br><span class="line">it is a state of mind. </span><br><span class="line">It is not a matter of rosy cheeks, red lips and supple knees. </span><br><span class="line">It is a matter of the will, a quality of the imagination, </span><br><span class="line">vigor of the emotions; </span><br><span class="line">it is the freshness of the deep spring of life.</span><br></pre></td></tr></table></figure><br>命令行参数为：<br><code>WF.exe -c test_letter.txt</code><br>测试结果如下：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">In file E:\Users\Lenovo\Desktop\test_letter.txt:</span><br><span class="line">Frequence of letter e is 12.02% (22)</span><br><span class="line">Frequence of letter i is 12.02% (22)</span><br><span class="line">Frequence of letter t is 12.02% (22)</span><br><span class="line">Frequence of letter o is 8.74% (16)</span><br><span class="line">Frequence of letter s is 8.74% (16)</span><br><span class="line">Frequence of letter a is 6.56% (12)</span><br><span class="line">Frequence of letter f is 6.01% (11)</span><br><span class="line">Frequence of letter n is 5.46% (10)</span><br><span class="line">Frequence of letter h is 4.37% (8)</span><br><span class="line">Frequence of letter l is 3.83% (7)</span><br><span class="line">Frequence of letter r is 3.83% (7)</span><br><span class="line">Frequence of letter m is 3.28% (6)</span><br><span class="line">Frequence of letter p is 2.73% (5)</span><br><span class="line">Frequence of letter d is 2.19% (4)</span><br><span class="line">Frequence of letter g is 1.64% (3)</span><br><span class="line">Frequence of letter u is 1.64% (3)</span><br><span class="line">Frequence of letter y is 1.64% (3)</span><br><span class="line">Frequence of letter k is 1.09% (2)</span><br><span class="line">Frequence of letter c is 0.55% (1)</span><br><span class="line">Frequence of letter q is 0.55% (1)</span><br><span class="line">Frequence of letter v is 0.55% (1)</span><br><span class="line">Frequence of letter w is 0.55% (1)</span><br></pre></td></tr></table></figure><br> 经过人工统计和与其他程序比对，测试结果正确。</p>
<h4 id="5-2-2-单词频率统计"><a href="#5-2-2-单词频率统计" class="headerlink" title="5.2.2 单词频率统计"></a>5.2.2 单词频率统计</h4><p>使用编写的简单测试文本test_word.txt进行测试，其文本内容为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Youth means a temperamental predominance of courage over timidity, of the appetite for adventure over the love of ease. </span><br><span class="line">This often exits in a man of 60, more than a boy of 20.</span><br><span class="line">nobody grows merely by the number of years; we grow old by deserting our ideas. </span><br><span class="line">Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul. </span><br><span class="line">Worry, fear bows the heart and turns the spirit back to dust.</span><br></pre></td></tr></table></figure></p>
<h5 id="1-测试-f"><a href="#1-测试-f" class="headerlink" title="(1) 测试 -f"></a>(1) 测试 -f</h5><p> 命令行参数为：<br><code>WF.exe -f .\test_word.txt</code><br> 测试结果为：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;to&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;years&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;adventure&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;and&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;appetite&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;back&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;bows&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;boy&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;but&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;courage&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;deserting&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;dust&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;ease&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;enthusiasm&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;exits&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;fear&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;for&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;give&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;grow&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;grows&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;heart&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;ideas&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;in&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;love&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;man&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;may&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;means&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;merely&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;more&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;nobody&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;number&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;often&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;old&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;our&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;predominance&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;skin&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;soul&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;spirit&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;temperamental&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;than&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;this&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;timidity&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;turns&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;up&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;we&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;worry&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;wrinkle&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;wrinkles&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;youth&quot; is 1.41% (1)</span><br></pre></td></tr></table></figure>
<p> 经过人工统计和与其他程序比对，测试结果正确。</p>
<h5 id="2-测试-n"><a href="#2-测试-n" class="headerlink" title="(2) 测试 -n"></a>(2) 测试 -n</h5><p> 命令行参数为：<br><code>WF.exe -f .\test_word -n 5</code><br> 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br></pre></td></tr></table></figure><br> 经过人工统计和与其他程序比对，测试结果正确。</p>
<h5 id="3-测试-d-和-s"><a href="#3-测试-d-和-s" class="headerlink" title="(3) 测试 -d 和 -s"></a>(3) 测试 -d 和 -s</h5><p> 设计目录结构为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">folder</span><br><span class="line">│   test_word.txt</span><br><span class="line">│   test_letter.txt  </span><br><span class="line">│</span><br><span class="line">└───subfolder1</span><br><span class="line">│   │   test_letter.txt</span><br><span class="line">│   </span><br><span class="line">└───subfolder2</span><br><span class="line">    │   test_word.txt</span><br></pre></td></tr></table></figure><br>1)命令行参数为：<br><code>WF.exe -d .\folder -n 5</code>使用-n参数使输出更明显<br> 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">In file .\folder\test_letter.txt:</span><br><span class="line">Words sum: 27  total sum: 52</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;of&quot; is 15.38% (8)</span><br><span class="line">Frequence of word &quot;a&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;is&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;the&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;it&quot; is 7.69% (4)</span><br><span class="line"></span><br><span class="line">In file .\folder\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br></pre></td></tr></table></figure><br> 经过人工统计和与其他程序比对，测试结果正确，即正确输出了该目录下文件的单词频率。<br> 2)命令行参数为：<br><code>WF.exe -d -s .\folder -n 5</code>使用-n参数使输出更明显<br> 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">In file .\folder\test_letter.txt:</span><br><span class="line">Words sum: 27  total sum: 52</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;of&quot; is 15.38% (8)</span><br><span class="line">Frequence of word &quot;a&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;is&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;the&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;it&quot; is 7.69% (4)</span><br><span class="line"></span><br><span class="line">In file .\folder\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br><span class="line"></span><br><span class="line">In file .\folder\subfolder1\test_letter.txt:</span><br><span class="line">Words sum: 27  total sum: 52</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;of&quot; is 15.38% (8)</span><br><span class="line">Frequence of word &quot;a&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;is&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;the&quot; is 9.62% (5)</span><br><span class="line">Frequence of word &quot;it&quot; is 7.69% (4)</span><br><span class="line"></span><br><span class="line">In file .\folder\subfolder2\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br></pre></td></tr></table></figure><br> 经过人工统计和与其他程序比对，测试结果正确，即正确递归地输出了该目录下所有文件的单词频率。</p>
<h5 id="4-测试-x"><a href="#4-测试-x" class="headerlink" title="(4) 测试 -x"></a>(4) 测试 -x</h5><p> 编写停用词文档，其文档内容如下：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">I am was were he she her his at a an they their of and the</span><br></pre></td></tr></table></figure><br> 命令行参数为：<br><code>WF.exe -x .\stopWordFile.txt -f .\test_word.txt -n 5</code>使用-n参数使输出更明显<br> 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Not stop Words sum: 50  total sum: 54</span><br><span class="line">The top 5 not stop words:</span><br><span class="line">Frequence of word &quot;by&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;to&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;years&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;adventure&quot; is 1.85% (1)</span><br></pre></td></tr></table></figure><br> 而原文档的 -f 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 5 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br></pre></td></tr></table></figure><br> 经过人工统计(去掉了停用词文件中的”a(3), of(6), and(1), the(7)”,单词为71-17=54个)和与其他程序比对，测试结果正确，即正确输出了该文件的单词频率。</p>
<h4 id="5-2-3-短语频率统计"><a href="#5-2-3-短语频率统计" class="headerlink" title="5.2.3 短语频率统计"></a>5.2.3 短语频率统计</h4><p>使用编写的简单测试文本test_phrase.txt进行测试，其内容如下：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Equality and Greatness Between persons of equal income there is no social distinction except</span><br><span class="line">the distinction of merit. Money is nothing; character, conduct and capacity are everything.</span><br><span class="line">Instead of all the workers being leveled down to low wage standards and all the rich leveled</span><br><span class="line">up to fashionbale income standards,everybody under a system of equal incomes would find</span><br><span class="line">his or her own natural level.There would be great people and ordinary people and little</span><br><span class="line">peolpe,but the great would always be those who had done great things,and never the idiot</span><br><span class="line">whose mother had spoiled them and whose father had left a hunred thousand a year;and the</span><br><span class="line">little would be persons of small minds and mean characters,and not poor persons who had</span><br><span class="line">never had a chance.That is why idiots are always in favour of inequality of income(their only</span><br><span class="line">chance of eminence),and the really great in favour of equality.</span><br></pre></td></tr></table></figure><br> 命令行参数为：<br><code>WF.exe .\test_phrase.txt -p 5</code><br><code>WF.exe .\test_pharse.txt -p 9</code><br> 测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_phrase.txt:</span><br><span class="line">Phrases sum: 13  total sum: 13</span><br><span class="line">Frequence of phrase &quot;conduct and capacity are everything&quot; is 7.69%</span><br><span class="line">Frequence of phrase &quot;their only chance of eminence&quot; is 7.69%</span><br></pre></td></tr></table></figure><br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_phrase.txt:</span><br><span class="line">Phrases sum: 13  total sum: 13</span><br><span class="line">There is no phrase that satisfies the condition!</span><br></pre></td></tr></table></figure><br> 经过人工统计(文件中5个单词组成的短语有两个，而无9个单词组成的短语)和与其他程序比对，测试结果正确，即正确输出了该文件的短语频率。</p>
<h4 id="5-2-4-动词形态归一化"><a href="#5-2-4-动词形态归一化" class="headerlink" title="5.2.4 动词形态归一化"></a>5.2.4 动词形态归一化</h4><p>编写动词形态文档，其文档内容如下：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">is was</span><br><span class="line">are were</span><br><span class="line">take takes took taken</span><br><span class="line">mean means</span><br><span class="line">exist exists</span><br></pre></td></tr></table></figure><br>对上述单词频率测试中的test_word.txt文档进行测试，其命令行参数为：<br><code>WF.exe -c .\test_word.txt -v .\verb.txt</code><br><code>WF.exe -f .\test_word.txt -n 20 -v .\verb.txt</code><br><code>WF.exe -x .\stopwords.txt -f .\test_word.txt -n 20 -v .\verb.txt</code><br><code>WF.exe .\test_word.txt -p 5 -v .\verb.txt</code><br>测试结果为：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Frequence of letter e is 13.58% (41)</span><br><span class="line">Frequence of letter t is 9.27% (28) </span><br><span class="line">Frequence of letter o is 8.94% (27) </span><br><span class="line">Frequence of letter r is 7.95% (24) </span><br><span class="line">Frequence of letter a is 7.28% (22)</span><br><span class="line">Frequence of letter n is 5.96% (18)</span><br><span class="line">Frequence of letter i is 5.63% (17)</span><br><span class="line">Frequence of letter s is 5.30% (16)</span><br><span class="line">Frequence of letter h is 3.97% (12)</span><br><span class="line">Frequence of letter m is 3.64% (11)</span><br><span class="line">Frequence of letter u is 3.64% (11)</span><br><span class="line">Frequence of letter y is 3.64% (11)</span><br><span class="line">Frequence of letter d is 2.98% (9)</span><br><span class="line">Frequence of letter f is 2.98% (9)</span><br><span class="line">Frequence of letter b is 2.65% (8)</span><br><span class="line">Frequence of letter l is 2.32% (7)</span><br><span class="line">Frequence of letter w is 2.32% (7)</span><br><span class="line">Frequence of letter p is 1.99% (6)</span><br><span class="line">Frequence of letter g is 1.66% (5)</span><br><span class="line">Frequence of letter v is 1.66% (5)</span><br><span class="line">Frequence of letter k is 1.32% (4)</span><br><span class="line">Frequence of letter c is 0.99% (3)</span><br><span class="line">Frequence of letter x is 0.33% (1)</span><br></pre></td></tr></table></figure><br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Words sum: 54  total sum: 71</span><br><span class="line">The top 20 words:</span><br><span class="line">Frequence of word &quot;the&quot; is 9.86% (7)</span><br><span class="line">Frequence of word &quot;of&quot; is 8.45% (6)</span><br><span class="line">Frequence of word &quot;a&quot; is 4.23% (3)</span><br><span class="line">Frequence of word &quot;by&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;to&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;years&quot; is 2.82% (2)</span><br><span class="line">Frequence of word &quot;adventure&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;and&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;appetite&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;back&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;bows&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;boy&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;but&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;courage&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;deserting&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;dust&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;ease&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;enthusiasm&quot; is 1.41% (1)</span><br><span class="line">Frequence of word &quot;exit&quot; is 1.41% (1)</span><br></pre></td></tr></table></figure><br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">In file .\test_word.txt:</span><br><span class="line">Not stop Words sum: 50  total sum: 54</span><br><span class="line">Frequence of word &quot;by&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;over&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;to&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;years&quot; is 3.70% (2)</span><br><span class="line">Frequence of word &quot;adventure&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;appetite&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;back&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;bows&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;boy&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;but&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;courage&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;deserting&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;dust&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;ease&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;enthusiasm&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;exit&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;fear&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;for&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;give&quot; is 1.85% (1)</span><br><span class="line">Frequence of word &quot;grow&quot; is 1.85% (1)</span><br></pre></td></tr></table></figure><br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> In file .\test_word.txt:</span><br><span class="line">Phrases sum: 7  total sum: 7</span><br><span class="line">Frequence of phrase &quot;youth mean a temperamental predominance of courage over timidity&quot; is 14.29%</span><br></pre></td></tr></table></figure><br> 经过人工统计(文件中的”means”和”exits”确实转换成了”mean”和”exit”)和与其他程序比对，四个测试结果均正确，即正确输出了文件在动词归一化后的相应频率。<br> 由于-d和-s参数均调用-f参数，故可以得出-d和-s同样可以接受-v参数，即动词归一化后再统计。</p>
<h4 id="5-2-5-出错情况测试："><a href="#5-2-5-出错情况测试：" class="headerlink" title="5.2.5 出错情况测试："></a>5.2.5 出错情况测试：</h4><p> 对命令行的各种错误情况进行测试：</p>
<h5 id="1-文本错误-路径错误，名字错误等-："><a href="#1-文本错误-路径错误，名字错误等-：" class="headerlink" title="1) 文本错误(路径错误，名字错误等)："></a>1) 文本错误(路径错误，名字错误等)：</h5><p> <code>wf.exe -f .\test.txt</code><br> <code>wf.exe -d -s .\test</code><br> 期待输出：<br> <code>File Not Exist!</code><br> <code>Dir File Not Exist!</code><br> 实际输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:\WF\dist&gt;wf.exe -f .\test</span><br><span class="line">File Not Exist!</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:\WF\dist&gt;wf.exe -d -s .\test</span><br><span class="line">Dir File Not Exist!</span><br></pre></td></tr></table></figure>
<h5 id="2-参数错误："><a href="#2-参数错误：" class="headerlink" title="2) 参数错误："></a>2) 参数错误：</h5><p> <code>wf.exe -f</code> 参数不足<br> <code>wf.exe -m -f</code> 非法参数<br> <code>wf.exe -f .\test_word.txt -v</code> 参数不足<br> 期待输出：<br> <code>Parameter Error!</code><br> <code>Parameter Error!</code><br> <code>Parameter Error!</code><br> 实际输出：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:\WF\dist&gt;wf.exe -f</span><br><span class="line">Parameter Error!</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:\WF\dist&gt;wf.exe -m -f</span><br><span class="line">Parameter Error!</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">E:\WF\dist&gt;wf.exe -f .\test_word.txt -v</span><br><span class="line">Parameter Error!</span><br></pre></td></tr></table></figure>
<h2 id="6，性能分析与代码质量分析"><a href="#6，性能分析与代码质量分析" class="headerlink" title="6，性能分析与代码质量分析"></a>6，性能分析与代码质量分析</h2><h4 id="6-1-代码质量分析："><a href="#6-1-代码质量分析：" class="headerlink" title="6.1 代码质量分析："></a>6.1 代码质量分析：</h4><p> 使用<strong>python</strong>提供的<strong>flake8</strong>对代码进行质量分析，结果如下：<br> <img src="/blog/2021/02/06/photo/7.png"><br> <img src="/blog/2021/02/06/photo/6.png"><br> 发现有许多代码不规范的地方，比如：<br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">at least two spaces before inline comment</span><br></pre></td></tr></table></figure></p>
<h5 id="在注释前要有两个空格"><a href="#在注释前要有两个空格" class="headerlink" title="在注释前要有两个空格"></a>在注释前要有两个空格</h5> <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">expected 2 blank lines, found 1</span><br></pre></td></tr></table></figure>
<h5 id="模块之间有两个空行"><a href="#模块之间有两个空行" class="headerlink" title="模块之间有两个空行"></a>模块之间有两个空行</h5><h5 id="经过对代码的优化，再次分析的结果如下："><a href="#经过对代码的优化，再次分析的结果如下：" class="headerlink" title="经过对代码的优化，再次分析的结果如下："></a>经过对代码的优化，再次分析的结果如下：</h5><p><img src="/blog/2021/02/06/photo/8.png"></p>
<h4 id="6-2-性能分析设计："><a href="#6-2-性能分析设计：" class="headerlink" title="6.2 性能分析设计："></a>6.2 性能分析设计：</h4><p> 使用<strong>python</strong>提供的<strong>cProfile</strong>对该词频统计程序进行性能分析，使用一个英文长篇文件《Pride and prejudice》(1M左右)进行测试，并对所有的函数调用次数与时间进行统计：<br> <code>python -m cProfile -s tottime WF.py -f .\Pride and prejudice.txt</code><br> 其中tottime表示该函数本身的执行时间，不包括该函数调用的子函数，cumtime表示该函数累计执行时间，包括该函数调用的子函数，性能测试结果如下：<br> <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">264098</span> function calls (<span class="number">264086</span> primitive calls) <span class="keyword">in</span> <span class="number">2.083</span> seconds</span><br><span class="line"></span><br><span class="line">Ordered by: internal time</span><br><span class="line"></span><br><span class="line">ncalls  tottime  percall  cumtime  percall filename:lineno(function)</span><br><span class="line">  <span class="number">6262</span>    <span class="number">1.731</span>    <span class="number">0.000</span>    <span class="number">1.731</span>    <span class="number">0.000</span> &#123;built-<span class="keyword">in</span> method builtins.<span class="built_in">print</span>&#125;</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.111</span>    <span class="number">0.111</span>    <span class="number">2.081</span>    <span class="number">2.081</span> WF.py:<span class="number">78</span>(WordFrequence)</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.102</span>    <span class="number">0.102</span>    <span class="number">0.102</span>    <span class="number">0.102</span> &#123;method <span class="string">&#x27;read&#x27;</span> of <span class="string">&#x27;_io.TextIOWrapper&#x27;</span> objects&#125;</span><br><span class="line"><span class="number">125860</span>    <span class="number">0.074</span>    <span class="number">0.000</span>    <span class="number">0.074</span>    <span class="number">0.000</span> WF.py:<span class="number">11</span>(IsWord)</span><br><span class="line"><span class="number">125089</span>    <span class="number">0.020</span>    <span class="number">0.000</span>    <span class="number">0.020</span>    <span class="number">0.000</span> &#123;method <span class="string">&#x27;get&#x27;</span> of <span class="string">&#x27;dict&#x27;</span> objects&#125;</span><br><span class="line">    <span class="number">27</span>    <span class="number">0.013</span>    <span class="number">0.000</span>    <span class="number">0.013</span>    <span class="number">0.000</span> &#123;method <span class="string">&#x27;replace&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.010</span>    <span class="number">0.010</span>    <span class="number">0.010</span>    <span class="number">0.010</span> &#123;method <span class="string">&#x27;split&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.008</span>    <span class="number">0.008</span>    <span class="number">0.008</span>    <span class="number">0.008</span> &#123;method <span class="string">&#x27;lower&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.008</span>    <span class="number">0.008</span>    <span class="number">0.009</span>    <span class="number">0.009</span> &#123;built-<span class="keyword">in</span> method builtins.<span class="built_in">sorted</span>&#125;</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.002</span>    <span class="number">0.002</span>    <span class="number">2.083</span>    <span class="number">2.083</span> WF.py:<span class="number">184</span>(main)</span><br><span class="line">  <span class="number">6260</span>    <span class="number">0.001</span>    <span class="number">0.000</span>    <span class="number">0.001</span>    <span class="number">0.000</span> WF.py:<span class="number">95</span>(&lt;<span class="keyword">lambda</span>&gt;)</span><br><span class="line">     <span class="number">1</span>    <span class="number">0.001</span>    <span class="number">0.001</span>    <span class="number">0.126</span>    <span class="number">0.126</span> WF.py:<span class="number">33</span>(GetText)</span><br><span class="line">    <span class="number">10</span>    <span class="number">0.001</span>    <span class="number">0.000</span>    <span class="number">0.001</span>    <span class="number">0.000</span> &#123;built-<span class="keyword">in</span> method nt.stat&#125;</span><br></pre></td></tr></table></figure><br>分析：<br>共264098个函数调用被监控，其中264086个是原生调用（不涉及递归），ncalls表示函数被调用的次数，tottime：函数内部消耗的总时间，percall：是tottime除以ncalls，一个函数每次调用平均消耗时间，cumtime：之前所有子函数消费时间的累计和，filename:lineno(function)：被分析函数所在文件名、行号、函数名。<br>可以看出输出方法print()被调用了6262次，其所耗时最长，其次是函数WordFrequence()，其是文件单词频率统计中所有函数中最耗时的一个，其代码已在前面展示，这里不再赘述。而该函数主要调用的子函数中，除了文件输入和输出外，子函数IsWord()被调用次数最多，耗时最长。</p>
<h4 id="6-3-性能分析改进："><a href="#6-3-性能分析改进：" class="headerlink" title="6.3 性能分析改进："></a>6.3 性能分析改进：</h4><p>子函数IsWord()用来判断一个词是否为规定的单词，先判断第一个字母是否为英文字母，再判断其后的所有字母是否为数字英文字母，若均成立则为单词，否则不为单词。原先的思路为遍历词的全部，若满足条件则置<code>flag=1</code>，否则<code>flag=0</code>，思考后发现，不需要全部遍历一遍，循环过程若出现不满足直接跳出，返回<code>false</code>，改进后的IsWord()如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># isWord(JudgedWord)：判断一个词是不是符合定义的单词</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">IsWord</span>(<span class="params">JudgedWord</span>):</span></span><br><span class="line">    <span class="keyword">if</span> JudgedWord == <span class="string">&quot;&quot;</span>:   <span class="comment"># 非空</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">elif</span> JudgedWord[<span class="number">0</span>] <span class="keyword">not</span> <span class="keyword">in</span> legalLetterList: <span class="comment"># 以字母开头</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="keyword">for</span> char <span class="keyword">in</span> JudgedWord:   </span><br><span class="line">            <span class="keyword">if</span> char <span class="keyword">not</span> <span class="keyword">in</span> legalWordList:   <span class="comment"># 由字母和数字组成</span></span><br><span class="line">                <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">True</span></span><br></pre></td></tr></table></figure>
<h4 id="6-4-大文本性能测试"><a href="#6-4-大文本性能测试" class="headerlink" title="6.4 大文本性能测试"></a>6.4 大文本性能测试</h4><p>使用20M左右的大文本测试 <code>-f</code> 功能：<br><code>python -m cProfile -s tottime WF.py -f .\test_big.txt</code><br>性能测试结果为：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">    <span class="number">6500958</span> function calls (<span class="number">6500946</span> primitive calls) <span class="keyword">in</span> <span class="number">4.792</span> seconds</span><br><span class="line"></span><br><span class="line"> Ordered by: internal time</span><br><span class="line"></span><br><span class="line"> ncalls  tottime  percall  cumtime  percall filename:lineno(function)</span><br><span class="line"><span class="number">3348256</span>    <span class="number">1.877</span>    <span class="number">0.000</span>    <span class="number">1.877</span>    <span class="number">0.000</span> WF.py:<span class="number">11</span>(IsWord)</span><br><span class="line">      <span class="number">1</span>    <span class="number">1.580</span>    <span class="number">1.580</span>    <span class="number">5.065</span>    <span class="number">5.065</span> WF.py:<span class="number">78</span>(WordFrequence)</span><br><span class="line"><span class="number">3136298</span>    <span class="number">0.541</span>    <span class="number">0.000</span>    <span class="number">0.541</span>    <span class="number">0.000</span> &#123;method <span class="string">&#x27;get&#x27;</span> of <span class="string">&#x27;dict&#x27;</span> objects&#125;</span><br><span class="line">     <span class="number">27</span>    <span class="number">0.350</span>    <span class="number">0.013</span>    <span class="number">0.350</span>    <span class="number">0.013</span> &#123;method <span class="string">&#x27;replace&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.245</span>    <span class="number">0.245</span>    <span class="number">0.245</span>    <span class="number">0.245</span> &#123;method <span class="string">&#x27;split&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.238</span>    <span class="number">0.238</span>    <span class="number">0.238</span>    <span class="number">0.238</span> &#123;method <span class="string">&#x27;lower&#x27;</span> of <span class="string">&#x27;str&#x27;</span> objects&#125;</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.126</span>    <span class="number">0.126</span>    <span class="number">0.126</span>    <span class="number">0.126</span> &#123;method <span class="string">&#x27;read&#x27;</span> of <span class="string">&#x27;_io.TextIOWrapper&#x27;</span> objects&#125;</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.066</span>    <span class="number">0.066</span>    <span class="number">0.069</span>    <span class="number">0.069</span> &#123;built-<span class="keyword">in</span> method builtins.<span class="built_in">sorted</span>&#125;</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.061</span>    <span class="number">0.061</span>    <span class="number">5.126</span>    <span class="number">5.126</span> WF.py:<span class="number">184</span>(main)</span><br><span class="line">      <span class="number">1</span>    <span class="number">0.029</span>    <span class="number">0.029</span>    <span class="number">0.745</span>    <span class="number">0.745</span> WF.py:<span class="number">33</span>(GetText)</span><br><span class="line">     <span class="number">23</span>    <span class="number">0.009</span>    <span class="number">0.000</span>    <span class="number">0.009</span>    <span class="number">0.000</span> &#123;built-<span class="keyword">in</span> method builtins.<span class="built_in">print</span>&#125;</span><br><span class="line">  <span class="number">15754</span>    <span class="number">0.004</span>    <span class="number">0.000</span>    <span class="number">0.004</span>    <span class="number">0.000</span> WF.py:<span class="number">95</span>(&lt;<span class="keyword">lambda</span>&gt;)</span><br><span class="line">     <span class="number">10</span>    <span class="number">0.001</span>    <span class="number">0.000</span>    <span class="number">0.001</span>    <span class="number">0.000</span> &#123;built-<span class="keyword">in</span> method nt.stat&#125;</span><br></pre></td></tr></table></figure>
<p>可见对一个20M左右的文本进行测试，所需时间为小5s，是可以接受的。<br>经测试，使用584MB的文本执行-c操作，时间约为50s;执行-f操作，时间约为25min。</p>
<h2 id="7，总结与感悟"><a href="#7，总结与感悟" class="headerlink" title="7，总结与感悟"></a>7，总结与感悟</h2><p> 通过这次软件工程个人项目的开发过程，我有以下收获：<br> 1，对一个项目的完整过程进行实现，使得我对软件开发过程以及软件的生命周期有了更深的理解；<br> 2，在项目中使用了python作为程序开发的语言，加深了我对python各方面语法等知识的理解与应用；<br> 3，对项目中软件测试以及性能分析的使用方法有所了解与掌握；<br> 4，当项目中遇到困难，要善于使用网络工具查找，增强了我解决问题的能力；<br> 5，要善于与同学交流，集思广益，找到解决问题的较佳方法。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://wx_mr_sanghy.gitee.io/blog/2021/02/06/photo/" data-id="ckkv17bvm0000akukhzt7cwst" data-title="软工个人项目——词频统计" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
</article>



  


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/02/">February 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2021/02/06/photo/">软工个人项目——词频统计</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 Huanyu Sang<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/blog/" class="mobile-nav-link">Home</a>
  
    <a href="/blog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/blog/js/jquery-3.4.1.min.js"></script>



  
<script src="/blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog/js/script.js"></script>





  </div>
</body>
</html>